﻿using System;
using System.Linq;
using System.IO;

namespace Task11
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = "C:\\Windows";
            GetFiles(path);
        }

        private static void GetFiles(string directory)
        {
            string[] files;
            try
            {
                files = Directory.GetFiles(directory, "*.exe");
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
            catch (UnauthorizedAccessException ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
            catch (System.Security.SecurityException)
            {
                Console.WriteLine("No permissions to access {0}", directory);
                return;
            }

            foreach (string file in files)
            {
                Console.WriteLine(file);
            }

            string[] directories = Directory.GetDirectories(directory);

            foreach (string dir in directories)
            {
                GetFiles(dir);
            }
        }
    }
}
